package lambdasinaction.chap8;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 流中的peek方法的设计初衷就是在流的每个元素恢复
 * 运行之前,插入执行一个动作
 * Created by ThinkPad on 2017/8/24.
 */
public class Peek {
    public static void main(String[] args) {
        List<Integer> result = Stream.of(2,3,4,5)
                .peek(x -> System.out.println("taking from Stream: " + x)).map(x -> x + 17)
                .peek(x -> System.out.println("after map: " + x)).filter(x -> x % 2 == 0)
                .peek(x -> System.out.println("after filter: " + x)).limit(3)
                .peek(x -> System.out.println("after limit: " + x)).collect(Collectors.toList());
    }
}
